package com.zlm.user.emp.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.base.PageEntity;
import com.zlm.common.constants.CodeConstants;
import com.zlm.common.dto.CoordinatesDto;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.user.emp.service.SysPartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: duyufu
 * @Date: 2019/5/5 15:53
 */
@RestController
@RequestMapping(value = "/partner")
public class SysPartnerController extends BaseController {

    @Autowired
    private SysPartnerService sysPartnerService;

    /**
     * 分页获取职业顾问
     * @param pageNumber
     * @param pageSize
     * @param lng
     * @param lat
     * @return
     */
    @GetMapping("/queryLocalPartner")
    public JsonResultDto queryLocalPartner(Integer pageNumber, Integer pageSize, String token, Double lng, Double lat) {
        try {
            CoordinatesDto coordinates = new CoordinatesDto(lng, lat);
            if (!coordinates.isValid()) {
                throw new RuntimeException(CodeConstants.CODE_PARAMS);
            }
            PageEntity page = sysPartnerService.queryLocalPartner(pageNumber, pageSize, coordinates, token);
            return success(page);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    @GetMapping("/queryMyPartner")
    public JsonResultDto queryMyPartner(Integer empId, Integer pageNumber, Integer pageSize) {
        try {
            PageEntity page = sysPartnerService.queryMyPartner(empId,pageNumber,pageSize);
            return success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

}
